using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace puyan_blogger {
    public partial class PloggerPasswordDialog : Form {

        private UserInfo userinfo = null;
        private bool canceled = true;

        public PloggerPasswordDialog() {
            InitializeComponent();
        }

        public string Username {
            get {
                if (!canceled && null != this.userinfo) {
                    return this.userinfo.Username;
                } else {
                    return "";
                }
            }
        }

        public string Password {
            get {
                if (!canceled && null != this.userinfo) {
                    return this.userinfo.Password;
                } else {
                    return "";
                }
            }
        }

        private void usernameTextbox_KeyPress(object sender, KeyPressEventArgs e) {
            if (e.KeyChar.Equals('\r') 
                && !(this.usernameTextbox.Text.Equals("")) 
                && !(this.passwordTextbox.Text.Equals(""))) {
                canceled = false;
                this.userinfo = new UserInfo(this.usernameTextbox.Text, this.passwordTextbox.Text);
                this.Close();
            }
        }

        private void passwordTextbox_KeyPress(object sender, KeyPressEventArgs e) {
            if (e.KeyChar.Equals('\r') 
                && !(this.usernameTextbox.Text.Equals("")) 
                && !(this.passwordTextbox.Text.Equals(""))) {
                canceled = false;
                this.userinfo = new UserInfo(this.usernameTextbox.Text, this.passwordTextbox.Text);
                this.Close();
            }
        }

  
    }
}